CREATE TABLE [dbo].[tb_INDICADOR]
(
[indicador_id] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (400) COLLATE Modern_Spanish_CI_AS NULL,
[Meta] [int] NULL,
[Accion] [int] NULL,
[Responsable] [int] NULL,
[Cantidad] [float] NULL,
[Monto] [decimal] (10, 0) NULL,
[Año] [int] NULL,
[Financiamiento] [int] NULL,
[Informacion] [int] NULL,
[Observaciones] [varchar] (500) COLLATE Modern_Spanish_CI_AS NULL,
[Nivel] [int] NULL,
[Usuario] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tb_INDICADOR_Usuario] DEFAULT (suser_sname())
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[agregarrepaticion] ON [dbo].[tb_INDICADOR]
FOR INSERT
AS
SET NOCOUNT ON
UPDATE [SageOld].[dbo].[tb_INDICADOR]
SET [Usuario]=(select idreparticion from tb_usuarios where ntuser = system_user)
WHERE indicador_id = (SELECT indicador_id from inserted)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[nocambiar] ON [dbo].[tb_INDICADOR]
FOR UPDATE
AS

SET NOCOUNT ON
if (SELECT Usuario FROM Inserted ) <> (select idreparticion from tb_usuarios where ntuser = system_user)
BEGIN
ROLLBACK transaction
RAISERROR('Solo el responsable del dato puede modificarlo.', 16,1)

END



GO
ALTER TABLE [dbo].[tb_INDICADOR] ADD CONSTRAINT [PK_INDICADOR] PRIMARY KEY CLUSTERED  ([indicador_id]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [acc] ON [dbo].[tb_INDICADOR] ([Accion]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [anio] ON [dbo].[tb_INDICADOR] ([Año]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [desc] ON [dbo].[tb_INDICADOR] ([Descripcion]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [met] ON [dbo].[tb_INDICADOR] ([Meta]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [aniometa] ON [dbo].[tb_INDICADOR] ([Meta], [Año]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [niv] ON [dbo].[tb_INDICADOR] ([Responsable]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_INDICADOR_TAB_ACCIONES] FOREIGN KEY ([Accion]) REFERENCES [dbo].[tb_ACCIONES] ([tab_accion_id])
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_INDICADOR_TAB_FINANCIAMIENTO] FOREIGN KEY ([Financiamiento]) REFERENCES [dbo].[tb_FINANCIAMIENTO] ([financiamiento_id])
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_tb_INDICADOR_tb_Organizaciones1] FOREIGN KEY ([Informacion]) REFERENCES [dbo].[tb_Organizaciones] ([idOrganizaciones])
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_INDICADOR_METAS] FOREIGN KEY ([Meta]) REFERENCES [dbo].[tb_METAS] ([tab_meta_id])
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_tb_INDICADOR_tb_NivelesEnsenanza1] FOREIGN KEY ([Nivel]) REFERENCES [dbo].[tb_NivelesEnsenanza] ([idNivelEnsenanza])
GO
ALTER TABLE [dbo].[tb_INDICADOR] WITH NOCHECK ADD CONSTRAINT [FK_tb_INDICADOR_tb_Organizaciones] FOREIGN KEY ([Responsable]) REFERENCES [dbo].[tb_Organizaciones] ([idOrganizaciones])
GO
